var app = getApp()
Component({
  properties: {
      liveList: {
        type:Array,
        value:[],
        observer:function(newVal, oldVal){
          if(!oldVal[0])return;
          for(var i = 0;i<oldVal.length;i++){
            if(newVal[i].item_id==oldVal[i].item_id){
              newVal[i] = oldVal[i]
            }
          }
          this.setData({
            liveList:newVal
          })
        }
      },
      showTitle:{
        type:Boolean,
        value:true
      },
      showIndex:{
        type:Number,
        value:0,
        observer:'listChange'
      },
      zIndex:{
        type:Boolean,
        value:true
      },
      scale:{
        type:Number,
        value:1,
      },
  },
  data: {
    liveList: [],
    is_test:app.globalData.is_test
  },
  ready() {
    this.setData({
      is_test:app.globalData.is_test
    })
  },
  methods: {
      //商品详情
      liveDetail(e) {
        if(this.long_click){
          this.long_click = false
          return
        } 
        var id = e.currentTarget.dataset.id;
        var status = e.currentTarget.dataset.status
        let roomId = [id]
        let customParams = encodeURIComponent(JSON.stringify({ sence: app.globalData.userInfo.id, from: 'live' }))
        let BaseUrl = app.globalData.is_test?'wx2b03c6e691cd7370':'api.comm.xingkonglian.net';
        if(status==102||status==101||status==105||status==106){
          wx.navigateToMiniProgram({
            appId: 'wxcbbd86b156ae4441',
          })
        } else {
          wx.navigateTo({
            url: `plugin-private://${BaseUrl}/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
          })
        }
      },
      // videoChange(e){
      //   if(!this.videocom1) return;
      //   if(e.currentTarget.id == this.videocom1.id || e.currentTarget.id == this.videocom2.id){
      //     if(e.detail.currentTime>=7){
      //       this.videocom1.seek(0)
      //       this.videocom2.seek(0)
      //       if(!this.videocom3) return;
      //       this.videocom3.seek(0)
      //       this.videocom4.seek(0)
      //     }
      //   }
      // },
      // listChange(e){
      //   var that = this;
      //   this.setData({
      //     zIndex:false
      //   })
      //   var text1 = 'video' + (e * 2 + 0)
      //   this.videocom1 = wx.createVideoContext(text1, that)
      //   this.videocom1.id = text1
      //   var text2 = 'video' + (e * 2 + 1)
      //   this.videocom2 = wx.createVideoContext(text2, that)
      //   this.videocom2.id = text2
      // },
      moreLive(){
        wx.switchTab({
            url: '/pages/tabbar/live/live',
        })
      },
      // calculate(){
      //   var that = this;
      //   const query = wx.createSelectorQuery().in(this);
      //   query.select('#videocom0').boundingClientRect();
      //   query.exec((res) => {
      //     that.triggerEvent('videoInfo', {res: res});
      //   });
      // },
      imgLoad(e){
        var index = e.currentTarget.dataset.index;
        this.data.liveList[index].imgShow=true;
        this.setData({
          liveList:this.data.liveList
        })
      },
      goHot(e){
        var index = e.currentTarget.dataset.index;
        this.data.liveList[index].is_show_mask=false;
        this.setData({
          liveList:this.data.liveList
        })
        wx.navigateTo({
          url: '/pages/module/hot/hot?q=' + this.data.liveList[index].cid_name,
        })
    },
    showMask(e){
        this.long_click = true
        var index = e.currentTarget.dataset.index;
        this.data.liveList.forEach(item=>{
          item.is_show_mask=false;
        })
        this.data.liveList[index].is_show_mask=true;
        this.setData({
          liveList:this.data.liveList
        })
    },
    hideMask(e){
      if(this.long_click){
        this.long_click = false
        return
      } 
        var index = e.currentTarget.dataset.index;
        this.data.liveList[index].is_show_mask=false;
        this.setData({
          liveList:this.data.liveList
        })
    }
  },
})